import { motormove } from "./alicloud/RPC";

export const handle = async (ws, message) => {
    try {
        const decoded = JSON.parse(message)
        if (decoded.from === "car1") {
            if (decoded.type === "MOTION") {
                const mode = decoded.data.mode
                console.log(mode)
                switch (mode) {
                    case 'Up':
                        return motormove({ degreeX: 0, degreeZ: 10 })
                    case 'Down':
                        return motormove({ degreeX: 0, degreeZ: -10 })
                    case 'Left':
                        return motormove({ degreeX: -10, degreeZ: 0 })
                    case 'Right':
                        return motormove({ degreeX: 10, degreeZ: 0 })
                    default:
                        break
                }
            }
        }
    } catch (error) {
        return Promise.reject(error)
    }
}